<?php
session_start();
define("IZ_ACCNAME","LOCAL");
if(is_file($_SESSION['IZ_CALPATH'].'includes/data/settings.php')) {
  include_once($_SESSION['IZ_CALPATH'].'includes/vars.php');
  include_once($_SESSION['IZ_CALPATH'].'includes/classes.php');  
  include_once($_SESSION['IZ_CALPATH'].'includes/functions_mini.php');
  include_once($_SESSION['IZ_CALPATH'].'includes/lang/'.$_SESSION['IZ_LANG'].'_core.php');
  include_once($_SESSION['IZ_CALPATH'].'includes/lang/'.$_SESSION['IZ_LANG'].'_admin.php');
  include_once($_SESSION['IZ_CALPATH'].'includes/lang/'.$_SESSION['IZ_LANG'].'_mini.php');
  $user = new user();
  if($_GET['ajax']) {
    get_month('nav',$_GET['month'],$_GET['year'],$_GET['cat']);
  } elseif(!isset($izeit)) { ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">

    <head profile="http://gmpg.org/xfn/11">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>iZeit Mini</title>
    <link rel="stylesheet" type="text/css" href="includes/mini_admin.css" />
    <link rel="stylesheet" type="text/css" href="includes/mini.css" />
    <script type="text/javascript" src="includes/js/ajax_mini.js"></script>
    <script type="text/javascript" src="includes/js/main.js"></script>
    <script type="text/javascript">
    //<![CDATA[
        function checkall(type) {
          catboxes = document.getElementById(type+'catnames').getElementsByTagName('input');
          if(document.getElementById(type+'catall').checked) {
            for(var i=0;i<catboxes.length;i++) {
              if((catboxes[i].type == 'checkbox') && (catboxes[i].id != 'upcoming'+type)){
                catboxes[i].checked = true;
              }
            }
          } else {
            for(var i=0;i<catboxes.length;i++) {
              if((catboxes[i].type == 'checkbox') && (catboxes[i].id != 'upcoming'+type)){
                catboxes[i].checked = false;
              }
            }
          }
        }
        function toggledisabled(type) {
          catboxes = document.getElementById(type+'catnames').getElementsByTagName('input');
          if(!document.getElementById('upcoming'+type).checked) {
            for(var i=0;i<catboxes.length;i++) {
              if((catboxes[i].type == 'checkbox') && (catboxes[i].id != 'upcoming'+type)){
                catboxes[i].disabled = true;
              }
            }
          } else {
            for(var i=0;i<catboxes.length;i++) {
              if((catboxes[i].type == 'checkbox') && (catboxes[i].id != 'upcoming'+type)){
                catboxes[i].disabled = false;
              }
            }
          }
        }
    <?php 
      if($_POST['p'] == '3') {
        echo '  var url = '.chr(34).$_SESSION['IZ_CALURL'].'mini.php'.chr(34).';'."\n";
        $showevents = intval($_POST['upcomingevent']);
        $showtodo = intval($_POST['upcomingtodo']);
        foreach($_POST as $cname => $cvalue) {
          if(substr($cname,0,3) == 'tod' && $cname != 'todocatall') {
            $todocatarray[substr($cname,3)] = $cvalue;
          } elseif(substr($cname,0,3) == 'eve' && $cname != 'eventcatall') {
            $eventcatarray[substr($cname,3)] = $cvalue;
          }
        }
        if(is_array($eventcatarray)) {
//              $eventcatnames = array_flip($eventcatarray);
          $eventcatstring = implode("-",$eventcatarray);
        } else {
          $eventcatstring = '';
        }
        if(($_POST['eventcatall'] == 'all') || ($showevents == 1 && empty($eventcatstring))) {
          $eventcatstring = 'all';
        }
        if($_POST['iztype'] == 'upcoming') {
          if(is_array($todocatarray)) {
//              $todocatnames = array_flip($todocatarray);
            $todocatstring = implode("-",$todocatarray);
          } else {
            $todocatstring = '';
          }
          if(($_POST['todocatall'] == 'all') || ($showtodo == 1 && empty($todocatstring))) {
            $todocatstring = 'all';
          }
        }
        echo '  var eventcatstring = '.chr(39).$eventcatstring.chr(39).';'."\n";
      }
    ?>
    //]]>
    </script>
    </head>
    <body>
    
    <div id="bannerback"><a href="<?php echo $_SESSION['IZ_CALURL']; ?>" id="banner"><?php echo $_SESSION['IZ_CALNAME']; ?></a></div>
    <div id="wrapper">
    <?php if(empty($_POST['p']) || ($_POST['start'])) { ?>
        <p><?php echo MIN_INTRO; ?></p>
        <h2><?php echo MIN_STEP1; ?></h2>
        <p><?php echo MIN_STEP1DESC; ?></p>
        <form action="mini.php" method="post">
            <table class="navtable">
              <tr>
                <td>
                  <label for="withoutnav"><img src="images/nonav.png" alt="<?php echo MIN_NONAV; ?>" /></label><br /><input type="radio" name="iztype" id="withoutnav" value="0" /><label for="withoutnav"><?php echo MIN_NONAV; ?></label>
                </td>
                <td>
                  <label for="withnav"><img src="images/withnav.png" alt="<?php echo MIN_WITHNAV; ?>" /></label><br /><input type="radio" name="iztype" id="withnav" value="1" checked="checked" /><label for="withnav"><?php echo MIN_WITHNAV; ?></label>
                </td>
              </tr>
              <tr>
                <td colspan="2">
                  <label for="upcoming"><img src="images/upcoming.png" alt="<?php echo MIN_UPCOMINGLONG; ?>" /></label><br /><input type="radio" name="iztype" id="upcoming" value="upcoming" /><label for="upcoming"><?php echo MIN_UPCOMINGLONG; ?></label>
                </td>
              </tr>
              <tr>
                <td>
                  &nbsp;
                </td>
                <td class="rightcell">
                  <button type="submit" name="go" value="two" id="nextbutton"><?php echo STR_NEXT; ?> &rsaquo;&rsaquo;</button>
                </td>
              </tr>
            </table>
            <input type="hidden" name="p" value="2" />
        </form>
    <?php } elseif($_POST['p'] == '2') {
        izsql();
        $catsql = "SELECT * FROM categories WHERE type = 'Event'";
        $todosql = "SELECT * FROM categories WHERE type = 'Task'";
    ?>
        <h2><?php echo MIN_STEP2; ?></h2>
        <form action="mini.php" method="post">
            <?php if($_POST['iztype'] == 'upcoming') { ?>
            <p><?php echo MIN_CALOPTS; ?></p>
            <table class="navtable fieldstable">
              <tr>
                <td class="parameter paddedcell">
                  <label><?php echo MIN_LINK; ?>&#58; </label>
                </td><td class="setting">
                  <input type="checkbox" name="showlink" value="1" id="showlink" checked="checked" /><label for="showlink"><?php echo STR_ENABLED; ?></label>
                </td>
              </tr>
              <tr>
                <td class="parameter paddedcell">
                  <label for="period"><?php echo MIN_NUMDAYS; ?>&#58; </label>
                </td><td class="setting">
                  <input type="text" name="period" value="7" id="period" />
                </td>
              </tr>
              <tr>
                <td class="parameter paddedcell">
                  <label><?php echo STR_DFORMAT; ?>&#58; </label>
                </td><td class="setting">
                  <input type="radio" name="dformat" value="izlongdate" id="dformatiz" /><label for="dformatiz"><?php echo iz_longdatehours(mktime()); ?></label><br />
                  <input type="radio" name="dformat" value="d/m/y" id="dformatdmy" /><label for="dformatdmy"><?php echo date("d/m/Y"); ?></label><br />
                  <input type="radio" name="dformat" value="Y-m-d" id="dformatymd" checked="checked" /><label for="dformatymd"><?php echo date("Y-m-d"); ?></label><br />
                  <input type="radio" name="dformat" value="custom" id="dformatcust" /><label for="dformatcust">Custom<input type="text" name="custdformat" size="10" id="custdformat" /></label><br />
                </td>
              </tr>
            </table>
            <?php } ?>
            <p><?php echo MIN_CATS; ?></p>
            <table class="navtable">
              <tr>
                <td colspan="2" class="paddedcell" id="eventcatnames">
                  <input type="checkbox" name="upcomingevent" value="1" checked="checked" id="upcomingevent" onclick="toggledisabled('event')" /><label for="upcomingevent"><strong><?php echo MIN_UPCEVENTSCHECK; ?></strong></label><br />
                  <?php
                    if(IZ_CALMODE == 'mysql') {
                      if($_SESSION['MYSQLi']) {
                        global $dblink;
                        $catqry = $dblink->query($catsql);
                        while($catrow = $catqry->fetch_object()) {
                          echo '<input type="checkbox" name="evecat'.$catrow->name.'" value="'.$catrow->id.'" id="evecat'.$catrow->name.'" /><label for="evecat'.$catrow->name.'">'.$catrow->name.'</label><br />'."\n";
                        }
                        $catqry->close();
                        if($_POST['iztype'] == 'upcoming') {
                          $todoqry = $dblink->query($todosql);
                          while($todocatrow = $todoqry->fetch_object()) {
                            $todooptions .= '<input type="checkbox" name="todcat'.$todocatrow->name.'" value="'.$todocatrow->id.'" id="todcat'.$todocatrow->name.'" /><label for="todcat'.$todocatrow->name.'">'.$todocatrow->name.'</label><br />'."\n";
                          }
                          $todoqry->close();
                        }
                      } else {
                        $catqry = mysql_query($catsql);
                        if($_POST['iztype'] == 'upcoming') {
                          $todoqry = mysql_query($todosql);
                          while($todocatrow = mysql_fetch_object($todoqry)) {
                            $todooptions .= '<input type="checkbox" name="todcat'.$todocatrow->name.'" value="'.$todocatrow->id.'" id="todcat'.$todocatrow->name.'" /><label for="todcat'.$todocatrow->name.'">'.$todocatrow->name.'</label><br />'."\n";
                          }
                        }
                        while($catrow = mysql_fetch_object($catqry)) {
                          echo '<input type="checkbox" name="evecat'.$catrow->name.'" value="'.$catrow->id.'" id="evecat'.$catrow->name.'" /><label for="evecat'.$catrow->name.'">'.$catrow->name.'</label><br />'."\n";
                        }
                      }
                    } elseif(IZ_CALMODE == 'postgre') {
                      $catsql = "SELECT * FROM categories WHERE type = 'event'";
                      $todosql = "SELECT * FROM categories WHERE type = 'task'";
                      $catqry = pg_query($catsql);
                      if($_POST['iztype'] == 'upcoming') {
                        $todoqry = pg_query($todosql);
                        while($todocatrow = pg_fetch_object($todoqry)) {
                          $todooptions .= '<input type="checkbox" name="todcat'.$todocatrow->name.'" value="'.$todocatrow->id.'" id="todcat'.$todocatrow->name.'" /><label for="todcat'.$todocatrow->name.'">'.$todocatrow->name.'</label><br />'."\n";
                        }
                      }
                      while($catrow = pg_fetch_object($catqry)) {
                        echo '<input type="checkbox" name="evecat'.$catrow->name.'" value="'.$catrow->id.'" id="evecat'.$catrow->name.'" /><label for="evecat'.$catrow->name.'">'.$catrow->name.'</label><br />'."\n";
                      }
                    } elseif(IZ_CALMODE == 'msq') {
                      $catqry = mssql_query($catsql);
                      if($_POST['iztype'] == 'upcoming') {
                        $todoqry = mssql_query($todosql);
                        while($todocatrow = mssql_fetch_object($todoqry)) {
                          $todooptions .= '<input type="checkbox" name="todcat'.$todocatrow->name.'" value="'.$todocatrow->id.'" id="todcat'.$todocatrow->name.'" /><label for="todcat'.$todocatrow->name.'">'.$todocatrow->name.'</label><br />'."\n";
                        }
                      }
                      while($catrow = mssql_fetch_object($catqry)) {
                        echo '<input type="checkbox" name="evecat'.$catrow->name.'" value="'.$catrow->id.'" id="evecat'.$catrow->name.'" /><label for="evecat'.$catrow->name.'">'.$catrow->name.'</label><br />'."\n";
                      }
                    }
                  ?>
                  <input type="checkbox" name="eventcatall" value="all" id="eventcatall" onclick="checkall('event')" /><label for="eventcatall"><?php echo STR_ALL; ?></label><br />
                </td>
              </tr>
              <?php if($_POST['iztype'] == 'upcoming') { ?>
              <tr>
                <td colspan="2" class="paddedcell" id="todocatnames">
                  <input type="checkbox" name="upcomingtodo" value="1" checked="checked" id="upcomingtodo" onclick="toggledisabled('todo')" /><label for="upcomingtodo"><strong><?php echo MIN_UPCTODOCHECK; ?></strong></label><br />
                  <?php echo $todooptions; ?>
                  <input type="checkbox" name="todocatall" value="all" id="todocatall" onclick="checkall('todo')" /><label for="todocatall"><?php echo STR_ALL; ?></label><br />
                </td>
              </tr>
              <?php } ?>
              <tr>
                <td class="leftcell">
                  <button type="submit" name="start" value="1" id="startagain">&lsaquo;&lsaquo; <?php echo MIN_STARTAGAIN; ?></button>
                </td>
                <td class="rightcell">
                  <button type="submit" name="go" value="three" id="nextbutton"><?php echo STR_NEXT; ?> &#62;&#62;</button>
                </td>
              </tr>
            </table>
            <input type="hidden" name="p" value="3" />
            <input type="hidden" name="iztype" value="<?php echo $_POST['iztype']; ?>" />
        </form>
    <?php 
    } elseif($_POST['p'] == '3') {
      if($_POST['iztype']) {
        $navstring = 'nav';
      } elseif($_POST['iztype'] == '0') {
        $navstring = 'nonav';
      }
      if(strlen(trim($_SERVER['DOCUMENT_ROOT'])) == 0) {
        $pathtouse = '/home/';
      } else {
        $lastslash = strrpos($_SERVER['SCRIPT_FILENAME'],'/');
        if($lastslash === FALSE) {
          $lastslash = strrpos($_SERVER['SCRIPT_FILENAME'],'\\');
          $pathtouse = substr($_SERVER['SCRIPT_FILENAME'],0,$lastslash).'\\';
        } else {
          $pathtouse = substr($_SERVER['SCRIPT_FILENAME'],0,$lastslash).'/';
        }
      }
    ?>
    <h2><?php echo MIN_STEP3; ?></h2>
   <h3><?php echo 'Insert the following code at the top of your page'; ?></h3>
    <textarea rows="1">
&#60;&#63;php session_start&#40;&#41;&#59; &#63;&#62;
    </textarea>
    <h3><?php echo MIN_HEAD; ?></h3>
    <textarea rows="9">
&#60;link rel=&#34;stylesheet&#34; type=&#34;text/css&#34; href=&#34;<?php echo $_SESSION['IZ_CALURL']; ?>includes/mini.css&#34; /&#62;
<?php if($_POST['iztype'] != 'upcoming') { ?>
&#60;script type=&#34;text/javascript&#34; src=&#34;<?php echo $_SESSION['IZ_CALURL']; ?>includes/js/main.js&#34;&#62;&#60;/script&#62;
&#60;script type=&#34;text/javascript&#34; src=&#34;<?php echo $_SESSION['IZ_CALURL']; ?>includes/js/ajax_mini.js&#34;&#62;&#60;/script&#62;
&#60;script type=&#34;text/javascript&#34;&#62;
&#47;&#47;&lt;&#33;&#91;CDATA&#91;
var url = &#39;<?php echo $_SESSION['IZ_CALURL']; ?>mini.php&#39;&#59;
var eventcatstring = '<?php echo $eventcatstring; ?>'&#59;
&#47;&#47;&#93;&#93;&gt;
&#60;/script&#62;
<?php } else {
  if($_POST['dformat'] == 'dformatcust') {
    $dformat = $_POST['custdformat'];
  } else {
    $dformat = $_POST['dformat'];
  }
} ?>
    </textarea>
    <h3><?php echo MIN_BODY; ?></h3>
    <p><?php echo str_replace('{0}',$pathtouse,MIN_REPLACEINST); ?></p>
    <textarea rows="6">
&#60;&#63;php
$_SESSION['IZ_CALPATH'] = &#39;<?php echo $pathtouse; ?>&#39;&#59;
$izeit = 1&#59; 
include $_SESSION['IZ_CALPATH'].&#39;mini.php&#39;&#59;
<?php if($_POST['iztype'] == 'upcoming') {
  $link = intval($_POST['showlink']);
  echo 'get_upcoming&#40;',$_POST['period'],',&#39;',$dformat,'&#39;,',$showtodo,',',$showevents,',',$link,',&#39;',$eventcatstring,'&#39;,&#39;',$todocatstring,'&#39;&#41;&#59;';
} else {
  if(empty($eventcatstring)) {
    $eventcatstring = 'all';
  }
  echo 'get_month&#40;&#39;',$navstring,'&#39;,0,0,&#39;',$eventcatstring,'&#39;&#41;&#59;';
} ?>

&#63;&#62;
    </textarea>
    <br />
    <fieldset class="preview">
    <legend><?php echo ADM_PREVIEW; ?></legend>
    <?php if($_POST['iztype'] == 'upcoming') {
      get_upcoming($_POST['period'],$dformat,$showtodo,$showevents,$link,$eventcatstring,$todocatstring);
    } else {
      get_month($navstring,0,0,$eventcatstring); 
    } ?>
    </fieldset><!-- end preview -->
<?php } ?>
    </div><!-- end wrapper -->
    <?php echo '<p class="gentext"><a href="&#x68;&#x74;&#x74;&#112;&#58;&#x2F;&#47;&#x77;&#x77;&#x77;&#46;&#105;&#x7A;&#x65;&#105;&#x74;&#x2E;&#110;&#x75;">iZeit '.IZ_CALVERSION.'</a><br />Copyright &copy;2005 - '.date("Y").' <a href="&#x68;&#x74;&#x74;&#112;&#58;&#x2F;&#47;&#x77;&#x77;&#x77;&#46;&#108;&#x75;&#x63;&#107;&#x79;&#x62;&#117;&#x64;&#100;&#x68;&#x61;&#46;&#x6E;&#117;">&#72;&#x61;&#x72;&#114;&#121;&#x20;&#74;&#x65;&#x6E;&#x6E;&#101;&#114;&#x77;&#x61;</a><a href="&#x68;&#x74;&#x74;&#112;&#58;&#x2F;&#47;&#x6C;&#x65;&#x67;&#104;&#117;&#x6D;&#x70;&#101;&#x64;&#x2E;&#99;&#x6F;&#109;">&#121;</a></p>'; ?>
    </body></html>
<?php } } else { ?>
<p><?php echo ERR_NOTINSTALLED; ?></p>
<?php }
if(isset($_GET['v'])) {
  var_dump($_SESSION);
}
//var_dump($_POST);
?>